{% extends "catalog/base_generic.html" %}

{% block title %}<title>我的借阅图书</title>{% endblock %}

{% block content %}
<h1>我的借阅图书</h1>

{% if bookinstance_list %}
    <div class="row">
        {% for bookinst in bookinstance_list %}
        <div class="col-md-4 mb-4">
            <div class="card">
                <div class="card-body">
                    <h5 class="card-title">{{ bookinst.book.title }}</h5>
                    <p class="card-text"><strong>作者:</strong> {{ bookinst.book.author }}</p>
                    <p class="card-text"><strong>应归还日期:</strong> {{ bookinst.due_back|date:"Y年m月d日" }}</p>
                    <p class="card-text"><strong>状态:</strong>
                        {% if bookinst.status == 'o' %}
                            <span class="text-danger">已借出</span>
                        {% else %}
                            <span class="text-success">可归还</span>
                        {% endif %}
                    </p>
                </div>
            </div>
        </div>
        {% empty %}
        <div class="col-12">
            <p>你当前没有借阅任何图书</p>
        </div>
        {% endfor %}
    </div>

    <!-- 分页导航 -->
    {% if is_paginated %}
        <div class="pagination mt-4">
            <span class="page-links">
                {% if page_obj.has_previous %}
                    <a href="{% url 'my-borrowed' %}?page={{ page_obj.previous_page_number }}">上一页</a>
                {% endif %}
                <span class="page-current">
                    第 {{ page_obj.number }} 页，共 {{ page_obj.paginator.num_pages }} 页
                </span>
                {% if page_obj.has_next %}
                    <a href="{% url 'my-borrowed' %}?page={{ page_obj.next_page_number }}">下一页</a>
                {% endif %}
            </span>
        </div>
    {% endif %}

{% else %}
    <p>你当前没有借阅任何图书</p>
{% endif %}
{% endblock %}

{% for bookinst in bookinstance_list %}
<li>
    <strong>书名:</strong> <a href="{% url 'book-detail' bookinst.book.pk %}">{{ bookinst.book.title }}</a><br>
    <strong>应归还日期:</strong> {{ bookinst.due_back|date:"Y年m月d日" }}<br>
    {% if user == bookinst.borrower or user.is_staff %}
        <a href="{% url 'renew-book' bookinst.pk %}" class="btn btn-sm btn-info">续借</a>
    {% endif %}
</li>
{% endfor %}